<?php
    $this->layout('base.phtml', [
        'title' => _('Account & data'),
        'canonical' => url_full('account'),
        'current_page' => 'account',
    ]);
?>

<div class="section section--longbottom">
    <div class="section__title">
        <h1><?= _('Account & data') ?></h1>
    </div>

    <p class="section__intro">
        <?= _f('You are registered since %s.', _date($current_user->created_at, 'dd MMMM Y')) ?>

        <?php if ($subscriptions_enabled): ?>
            <br />
            <?php if ($current_user->isSubscriptionExempted()): ?>
                <?= _('You have a <strong>free subscription</strong>!&nbsp;😊') ?>
            <?php elseif ($current_user->isSubscriptionOverdue()): ?>
                <?= _f('<strong>Your subscription expired on %s.</strong>', _date($current_user->subscription_expired_at, 'dd MMMM Y')) ?>
            <?php else: ?>
                <?= _f('Your subscription will expire on <strong>%s.</strong>', _date($current_user->subscription_expired_at, 'dd MMMM Y')) ?>
            <?php endif; ?>
        <?php endif; ?>
    </p>

    <?= $this->include('alerts/_error.phtml', ['message' => $error]) ?>

    <nav class="groupnav">
        <?php if (!$current_user->validated_at || $subscriptions_enabled): ?>
            <h2 class="groupnav__title"><?= _('Account') ?></h2>

            <ul class="groupnav__container">
                <?php if (!$current_user->validated_at): ?>
                    <li class="groupnav__item groupnav__item--featured groupnav__item--validate">
                        <a class="groupnav__anchor" href="<?= url('account validation') ?>">
                            <?= _('Validate your account') ?>
                        </a>
                    </li>
                <?php elseif ($subscriptions_enabled && $current_user->subscription_account_id): ?>
                    <li class="groupnav__item groupnav__item--subscription <?= $current_user->isSubscriptionOverdue() ? 'groupnav__item--featured' : '' ?>">
                        <a class="groupnav__anchor" href="<?= url('subscription') ?>">
                            <?= _('Manage your subscription') ?>
                        </a>
                    </li>
                <?php elseif ($subscriptions_enabled): ?>
                    <li class="groupnav__item groupnav__item--create groupnav__item--featured">
                        <form method="post" action="<?= url('create subscription account') ?>">
                            <input type="hidden" name="csrf" value="<?= csrf_token() ?>" />
                            <button class="groupnav__button" type="submit">
                                <?= _('Create your payment account') ?>
                            </button>
                        </form>
                    </li>
                <?php endif; ?>
            </ul>
        <?php endif; ?>

        <?php if ($beta_enabled): ?>
            <h2 class="groupnav__title"><?= _('Sharing') ?></h2>

            <ul class="groupnav__container">
                <li class="groupnav__item groupnav__item--mastodon">
                    <a class="groupnav__anchor" href="<?= url('mastodon') ?>">
                        <?= _('Configure sharing to Mastodon') ?>
                    </a>
                </li>
            </ul>
        <?php endif; ?>

        <h2 class="groupnav__title"><?= _('Data') ?></h2>

        <ul class="groupnav__container">
            <?php if ($pocket_enabled && !$current_user->isBlocked()): ?>
                <li class="groupnav__item groupnav__item--import">
                    <a class="groupnav__anchor" href="<?= url('pocket') ?>">
                        <?= _('Import your data from Pocket') ?>
                    </a>
                </li>
            <?php endif; ?>

            <?php if (!$current_user->isBlocked()): ?>
                <li class="groupnav__item groupnav__item--import">
                    <a class="groupnav__anchor" href="<?= url('opml') ?>">
                        <?= _('Import your data from an <abbr>OPML</abbr> file') ?>
                    </a>
                </li>
            <?php endif; ?>

            <li class="groupnav__item groupnav__item--data">
                <a class="groupnav__anchor" href="<?= url('exportation') ?>">
                    <?= _('Download your data') ?>
                </a>
            </li>
        </ul>

        <h2 class="groupnav__title"><?= _('Security') ?></h2>

        <ul class="groupnav__container">
            <li class="groupnav__item groupnav__item--credentials">
                <a class="groupnav__anchor" href="<?= url('security') ?>">
                    <?= _('Manage your credentials') ?>
                </a>
            </li>

            <li class="groupnav__item groupnav__item--sessions">
                <a class="groupnav__anchor" href="<?= url('sessions') ?>">
                    <?= _('Manage your sessions') ?>
                </a>
            </li>

            <li class="groupnav__item groupnav__item--delete">
                <a class="groupnav__anchor" href="<?= url('account deletion') ?>">
                    <?= _('Delete your account?') ?>
                </a>
            </li>
        </ul>
    </nav>
</div>
